WPF:DataGrid按自定义逻辑改变文字颜色 |
您所在的位置:网站首页 › wpf datagridcomboxcolum › WPF:DataGrid按自定义逻辑改变文字颜色 |
主要利用IValueConverter 接口,该转换器接口提供一种将自定义逻辑应用于绑定的方法。 该转换器似乎还有更多骚操作,暂时没有深究。 转载自:WPF DataGrid 动态转换字体颜色 .XAML:需要加入Resources,设置需要改变颜色的对应栏的CellStyle .CS:实现转换器 public class ColorConverter:IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value != null) { int id; if (int.TryParse(value.ToString(), out id))//这里改成你需要的逻辑 { if (id % 2 == 1) { return Brushes.Red; } } } return Brushes.Black; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return null; } } |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |